﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;

namespace AGaugeApp
{
    [Description("Displays a value on an analog gauge. Raises an event if the value enters one of the definable ranges."
        ), DefaultEvent("ValueInRangeChanged"), ToolboxBitmap(typeof (AGauge), "AGauge.bmp")]
    public class AGauge : Control
    {
        #region Delegates

        public delegate void ValueInRangeChangedDelegate(object sender, ValueInRangeChangedEventArgs e);

        #endregion

        #region NeedleColorEnum enum

        public enum NeedleColorEnum
        {
            Gray,
            Red,
            Green,
            Blue,
            Yellow,
            Violet,
            Magenta
        }

        #endregion

        private const byte NUMOFCAPS = 5;
        private const byte NUMOFRANGES = 5;
        private const byte ZERO = 0;
        private readonly string[] m_CapText = new[] {"", "", "", "", ""};
        private readonly bool[] m_valueIsInRange = new bool[5];

        private IContainer components;
        private bool drawGaugeBackground = true;
        private float fontBoundY1;
        private float fontBoundY2;
        private Bitmap gaugeBitmap;
        private Color m_BaseArcColor = Color.Gray;
        private int m_BaseArcRadius = 80;
        private int m_BaseArcStart = 0x87;
        private int m_BaseArcSweep = 270;
        private int m_BaseArcWidth = 2;
        private Color[] m_CapColor = new[] {Color.Black, Color.Black, Color.Black, Color.Black, Color.Black};
        private byte m_CapIdx = 1;

        private Point[] m_CapPosition = new[]
            {new Point(10, 10), new Point(10, 10), new Point(10, 10), new Point(10, 10), new Point(10, 10)};

        private Point m_Center = new Point(100, 100);
        private float m_MaxValue = 400f;
        private float m_MinValue = -100f;
        private NeedleColorEnum m_NeedleColor1;
        private Color m_NeedleColor2;
        private int m_NeedleRadius;
        private int m_NeedleType;
        private int m_NeedleWidth;
        private Color[] m_RangeColor;
        private bool[] m_RangeEnabled;
        private float[] m_RangeEndValue;
        private byte m_RangeIdx;
        private int[] m_RangeInnerRadius;
        private int[] m_RangeOuterRadius;
        private float[] m_RangeStartValue;
        private Color m_ScaleLinesInterColor = Color.Black;
        private int m_ScaleLinesInterInnerRadius = 0x49;
        private int m_ScaleLinesInterOuterRadius = 80;
        private int m_ScaleLinesInterWidth = 1;
        private Color m_ScaleLinesMajorColor = Color.Black;
        private int m_ScaleLinesMajorInnerRadius = 70;
        private int m_ScaleLinesMajorOuterRadius = 80;
        private float m_ScaleLinesMajorStepValue = 50f;
        private int m_ScaleLinesMajorWidth = 2;
        private Color m_ScaleLinesMinorColor = Color.Gray;
        private int m_ScaleLinesMinorInnerRadius = 0x4b;
        private int m_ScaleLinesMinorNumOf = 9;
        private int m_ScaleLinesMinorOuterRadius = 80;
        private int m_ScaleLinesMinorWidth = 1;
        private Color m_ScaleNumbersColor;
        private string m_ScaleNumbersFormat;
        private int m_ScaleNumbersRadius;
        private int m_ScaleNumbersRotation;
        private int m_ScaleNumbersStartScaleLine;
        private int m_ScaleNumbersStepScaleLines;
        private float m_value;

        public AGauge()
        {
            var flagArray2 = new bool[5];
            flagArray2[0] = true;
            flagArray2[1] = true;
            m_RangeEnabled = flagArray2;
            m_RangeColor = new[]
                {
                    Color.LightGreen, Color.Red, Color.FromKnownColor(KnownColor.Control),
                    Color.FromKnownColor(KnownColor.Control), Color.FromKnownColor(KnownColor.Control)
                };
            var numArray = new float[5];
            numArray[0] = -100f;
            numArray[1] = 300f;
            m_RangeStartValue = numArray;
            var numArray2 = new float[5];
            numArray2[0] = 300f;
            numArray2[1] = 400f;
            m_RangeEndValue = numArray2;
            m_RangeInnerRadius = new[] {70, 70, 70, 70, 70};
            m_RangeOuterRadius = new[] {80, 80, 80, 80, 80};
            m_ScaleNumbersRadius = 0x5f;
            m_ScaleNumbersColor = Color.Black;
            m_ScaleNumbersStepScaleLines = 1;
            m_NeedleRadius = 80;
            m_NeedleColor2 = Color.DimGray;
            m_NeedleWidth = 2;
            InitializeComponent();
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }

        public bool AllowDrop
        {
            get { return false; }
            set { }
        }

        public bool AutoSize
        {
            get { return false; }
            set { }
        }

        public override Color BackColor
        {
            get { return base.BackColor; }
            set
            {
                base.BackColor = value;
                drawGaugeBackground = true;
                Refresh();
            }
        }

        public override ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set
            {
                base.BackgroundImageLayout = value;
                drawGaugeBackground = true;
                Refresh();
            }
        }

        [Description("The color of the base arc."), Category("AGauge"), Browsable(true)]
        public Color BaseArcColor
        {
            get { return m_BaseArcColor; }
            set
            {
                if (m_BaseArcColor != value)
                {
                    m_BaseArcColor = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The radius of the base arc."), Browsable(true), Category("AGauge")]
        public int BaseArcRadius
        {
            get { return m_BaseArcRadius; }
            set
            {
                if (m_BaseArcRadius != value)
                {
                    m_BaseArcRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The start angle of the base arc."), Browsable(true)]
        public int BaseArcStart
        {
            get { return m_BaseArcStart; }
            set
            {
                if (m_BaseArcStart != value)
                {
                    m_BaseArcStart = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Description("The sweep angle of the base arc."), Category("AGauge")]
        public int BaseArcSweep
        {
            get { return m_BaseArcSweep; }
            set
            {
                if (m_BaseArcSweep != value)
                {
                    m_BaseArcSweep = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The width of the base arc.")]
        public int BaseArcWidth
        {
            get { return m_BaseArcWidth; }
            set
            {
                if (m_BaseArcWidth != value)
                {
                    m_BaseArcWidth = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description(
            "The caption index. set this to a value of 0 up to 4 to change the corresponding caption's properties."),
         Browsable(true), Category("AGauge"), RefreshProperties(RefreshProperties.All)]
        public byte Cap_Idx
        {
            get { return m_CapIdx; }
            set
            {
                if (((m_CapIdx != value) && (0 <= value)) && (value < 5))
                {
                    m_CapIdx = value;
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The color of the caption text.")]
        private Color CapColor
        {
            get { return m_CapColor[m_CapIdx]; }
            set
            {
                if (m_CapColor[m_CapIdx] != value)
                {
                    m_CapColor[m_CapIdx] = value;
                    CapColors = m_CapColor;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(false)]
        public Color[] CapColors
        {
            get { return m_CapColor; }
            set { m_CapColor = value; }
        }

        [Category("AGauge"), Browsable(true), Description("The position of the caption.")]
        public Point CapPosition
        {
            get { return m_CapPosition[m_CapIdx]; }
            set
            {
                if (m_CapPosition[m_CapIdx] != value)
                {
                    m_CapPosition[m_CapIdx] = value;
                    CapsPosition = m_CapPosition;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(false)]
        public Point[] CapsPosition
        {
            get { return m_CapPosition; }
            set { m_CapPosition = value; }
        }

        [Browsable(false)]
        public string[] CapsText
        {
            get { return m_CapText; }
            set
            {
                for (var i = 0; i < 5; i++)
                {
                    m_CapText[i] = value[i];
                }
            }
        }

        [Description("The text of the caption."), Category("AGauge"), Browsable(true)]
        public string CapText
        {
            get { return m_CapText[m_CapIdx]; }
            set
            {
                if (m_CapText[m_CapIdx] != value)
                {
                    m_CapText[m_CapIdx] = value;
                    CapsText = m_CapText;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The center of the gauge (in the control's client area)."), Category("AGauge"), Browsable(true)]
        public Point Center
        {
            get { return m_Center; }
            set
            {
                if (m_Center != value)
                {
                    m_Center = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        public override Font Font
        {
            get { return base.Font; }
            set
            {
                base.Font = value;
                drawGaugeBackground = true;
                Refresh();
            }
        }

        public bool ForeColor
        {
            get { return false; }
            set { }
        }

        public bool ImeMode
        {
            get { return false; }
            set { }
        }

        [Description("The maximum value to show on the scale."), Category("AGauge"), Browsable(true)]
        public float MaxValue
        {
            get { return m_MaxValue; }
            set
            {
                if ((m_MaxValue != value) && (value > m_MinValue))
                {
                    m_MaxValue = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The minimum value to show on the scale."), Category("AGauge"), Browsable(true)]
        public float MinValue
        {
            get { return m_MinValue; }
            set
            {
                if ((m_MinValue != value) && (value < m_MaxValue))
                {
                    m_MinValue = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The first color of the needle.")]
        public NeedleColorEnum NeedleColor1
        {
            get { return m_NeedleColor1; }
            set
            {
                if (m_NeedleColor1 != value)
                {
                    m_NeedleColor1 = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The second color of the needle."), Browsable(true)]
        public Color NeedleColor2
        {
            get { return m_NeedleColor2; }
            set
            {
                if (m_NeedleColor2 != value)
                {
                    m_NeedleColor2 = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The radius of the needle."), Category("AGauge"), Browsable(true)]
        public int NeedleRadius
        {
            get { return m_NeedleRadius; }
            set
            {
                if (m_NeedleRadius != value)
                {
                    m_NeedleRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description(
            "The type of the needle, currently only type 0 and 1 are supported. Type 0 looks nicers but if you experience performance problems you might consider using type 1."
            ), Category("AGauge"), Browsable(true)]
        public int NeedleType
        {
            get { return m_NeedleType; }
            set
            {
                if (m_NeedleType != value)
                {
                    m_NeedleType = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The width of the needle."), Category("AGauge"), Browsable(true)]
        public int NeedleWidth
        {
            get { return m_NeedleWidth; }
            set
            {
                if (m_NeedleWidth != value)
                {
                    m_NeedleWidth = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true),
         Description("The range index. set this to a value of 0 up to 4 to change the corresponding range's properties."
             ), Category("AGauge"), RefreshProperties(RefreshProperties.All)]
        public byte Range_Idx
        {
            get { return m_RangeIdx; }
            set
            {
                if (((m_RangeIdx != value) && (0 <= value)) && (value < 5))
                {
                    m_RangeIdx = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true), Description("The color of the range.")]
        public Color RangeColor
        {
            get { return m_RangeColor[m_RangeIdx]; }
            set
            {
                if (m_RangeColor[m_RangeIdx] != value)
                {
                    m_RangeColor[m_RangeIdx] = value;
                    RangesColor = m_RangeColor;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Description("Enables or disables the range selected by Range_Idx."), Category("AGauge")]
        public bool RangeEnabled
        {
            get { return m_RangeEnabled[m_RangeIdx]; }
            set
            {
                if (m_RangeEnabled[m_RangeIdx] != value)
                {
                    m_RangeEnabled[m_RangeIdx] = value;
                    RangesEnabled = m_RangeEnabled;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The end value of the range. Must be greater than RangeStartValue."),
         Browsable(true)]
        public float RangeEndValue
        {
            get { return m_RangeEndValue[m_RangeIdx]; }
            set
            {
                if ((m_RangeEndValue[m_RangeIdx] != value) && (m_RangeStartValue[m_RangeIdx] < value))
                {
                    m_RangeEndValue[m_RangeIdx] = value;
                    RangesEndValue = m_RangeEndValue;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The inner radius of the range.")]
        public int RangeInnerRadius
        {
            get { return m_RangeInnerRadius[m_RangeIdx]; }
            set
            {
                if (m_RangeInnerRadius[m_RangeIdx] != value)
                {
                    m_RangeInnerRadius[m_RangeIdx] = value;
                    RangesInnerRadius = m_RangeInnerRadius;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true), Description("The inner radius of the range.")]
        public int RangeOuterRadius
        {
            get { return m_RangeOuterRadius[m_RangeIdx]; }
            set
            {
                if (m_RangeOuterRadius[m_RangeIdx] != value)
                {
                    m_RangeOuterRadius[m_RangeIdx] = value;
                    RangesOuterRadius = m_RangeOuterRadius;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(false)]
        public Color[] RangesColor
        {
            get { return m_RangeColor; }
            set { m_RangeColor = value; }
        }

        [Browsable(false)]
        public bool[] RangesEnabled
        {
            get { return m_RangeEnabled; }
            set { m_RangeEnabled = value; }
        }

        [Browsable(false)]
        public float[] RangesEndValue
        {
            get { return m_RangeEndValue; }
            set { m_RangeEndValue = value; }
        }

        [Browsable(false)]
        public int[] RangesInnerRadius
        {
            get { return m_RangeInnerRadius; }
            set { m_RangeInnerRadius = value; }
        }

        [Browsable(false)]
        public int[] RangesOuterRadius
        {
            get { return m_RangeOuterRadius; }
            set { m_RangeOuterRadius = value; }
        }

        [Browsable(false)]
        public float[] RangesStartValue
        {
            get { return m_RangeStartValue; }
            set { m_RangeStartValue = value; }
        }

        [Description("The start value of the range, must be less than RangeEndValue."), Category("AGauge"),
         Browsable(true)]
        public float RangeStartValue
        {
            get { return m_RangeStartValue[m_RangeIdx]; }
            set
            {
                if ((m_RangeStartValue[m_RangeIdx] != value) && (value < m_RangeEndValue[m_RangeIdx]))
                {
                    m_RangeStartValue[m_RangeIdx] = value;
                    RangesStartValue = m_RangeStartValue;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description(
            "The color of the inter scale lines which are the middle scale lines for an uneven number of minor scale lines."
            ), Category("AGauge"), Browsable(true)]
        public Color ScaleLinesInterColor
        {
            get { return m_ScaleLinesInterColor; }
            set
            {
                if (m_ScaleLinesInterColor != value)
                {
                    m_ScaleLinesInterColor = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description(
            "The inner radius of the inter scale lines which are the middle scale lines for an uneven number of minor scale lines."
            ), Browsable(true), Category("AGauge")]
        public int ScaleLinesInterInnerRadius
        {
            get { return m_ScaleLinesInterInnerRadius; }
            set
            {
                if (m_ScaleLinesInterInnerRadius != value)
                {
                    m_ScaleLinesInterInnerRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"),
         Description(
             "The outer radius of the inter scale lines which are the middle scale lines for an uneven number of minor scale lines."
             )]
        public int ScaleLinesInterOuterRadius
        {
            get { return m_ScaleLinesInterOuterRadius; }
            set
            {
                if (m_ScaleLinesInterOuterRadius != value)
                {
                    m_ScaleLinesInterOuterRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description(
            "The width of the inter scale lines which are the middle scale lines for an uneven number of minor scale lines."
            ), Browsable(true), Category("AGauge")]
        public int ScaleLinesInterWidth
        {
            get { return m_ScaleLinesInterWidth; }
            set
            {
                if (m_ScaleLinesInterWidth != value)
                {
                    m_ScaleLinesInterWidth = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The color of the major scale lines."), Category("AGauge"), Browsable(true)]
        public Color ScaleLinesMajorColor
        {
            get { return m_ScaleLinesMajorColor; }
            set
            {
                if (m_ScaleLinesMajorColor != value)
                {
                    m_ScaleLinesMajorColor = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The inner radius of the major scale lines."), Browsable(true), Category("AGauge")]
        public int ScaleLinesMajorInnerRadius
        {
            get { return m_ScaleLinesMajorInnerRadius; }
            set
            {
                if (m_ScaleLinesMajorInnerRadius != value)
                {
                    m_ScaleLinesMajorInnerRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The outer radius of the major scale lines."), Category("AGauge"), Browsable(true)]
        public int ScaleLinesMajorOuterRadius
        {
            get { return m_ScaleLinesMajorOuterRadius; }
            set
            {
                if (m_ScaleLinesMajorOuterRadius != value)
                {
                    m_ScaleLinesMajorOuterRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The step value of the major scale lines."), Browsable(true), Category("AGauge")]
        public float ScaleLinesMajorStepValue
        {
            get { return m_ScaleLinesMajorStepValue; }
            set
            {
                if ((m_ScaleLinesMajorStepValue != value) && (value > 0f))
                {
                    m_ScaleLinesMajorStepValue = Math.Max(Math.Min(value, m_MaxValue), m_MinValue);
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The width of the major scale lines."), Browsable(true)]
        public int ScaleLinesMajorWidth
        {
            get { return m_ScaleLinesMajorWidth; }
            set
            {
                if (m_ScaleLinesMajorWidth != value)
                {
                    m_ScaleLinesMajorWidth = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Description("The color of the minor scale lines."), Category("AGauge")]
        public Color ScaleLinesMinorColor
        {
            get { return m_ScaleLinesMinorColor; }
            set
            {
                if (m_ScaleLinesMinorColor != value)
                {
                    m_ScaleLinesMinorColor = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The inner radius of the minor scale lines.")]
        public int ScaleLinesMinorInnerRadius
        {
            get { return m_ScaleLinesMinorInnerRadius; }
            set
            {
                if (m_ScaleLinesMinorInnerRadius != value)
                {
                    m_ScaleLinesMinorInnerRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The number of minor scale lines."), Browsable(true)]
        public int ScaleLinesMinorNumOf
        {
            get { return m_ScaleLinesMinorNumOf; }
            set
            {
                if (m_ScaleLinesMinorNumOf != value)
                {
                    m_ScaleLinesMinorNumOf = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Description("The outer radius of the minor scale lines."), Browsable(true)]
        public int ScaleLinesMinorOuterRadius
        {
            get { return m_ScaleLinesMinorOuterRadius; }
            set
            {
                if (m_ScaleLinesMinorOuterRadius != value)
                {
                    m_ScaleLinesMinorOuterRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The width of the minor scale lines."), Category("AGauge"), Browsable(true)]
        public int ScaleLinesMinorWidth
        {
            get { return m_ScaleLinesMinorWidth; }
            set
            {
                if (m_ScaleLinesMinorWidth != value)
                {
                    m_ScaleLinesMinorWidth = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Description("The color of the scale numbers."), Category("AGauge")]
        public Color ScaleNumbersColor
        {
            get { return m_ScaleNumbersColor; }
            set
            {
                if (m_ScaleNumbersColor != value)
                {
                    m_ScaleNumbersColor = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Description("The format of the scale numbers."), Browsable(true), Category("AGauge")]
        public string ScaleNumbersFormat
        {
            get { return m_ScaleNumbersFormat; }
            set
            {
                if (m_ScaleNumbersFormat != value)
                {
                    m_ScaleNumbersFormat = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true), Description("The radius of the scale numbers.")]
        public int ScaleNumbersRadius
        {
            get { return m_ScaleNumbersRadius; }
            set
            {
                if (m_ScaleNumbersRadius != value)
                {
                    m_ScaleNumbersRadius = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true),
         Description(
             "The angle relative to the tangent of the base arc at a scale line that is used to rotate numbers. set to 0 for no rotation or e.g. set to 90."
             )]
        public int ScaleNumbersRotation
        {
            get { return m_ScaleNumbersRotation; }
            set
            {
                if (m_ScaleNumbersRotation != value)
                {
                    m_ScaleNumbersRotation = value;
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true),
         Description("The number of the scale line to start writing numbers next to.")]
        public int ScaleNumbersStartScaleLine
        {
            get { return m_ScaleNumbersStartScaleLine; }
            set
            {
                if (m_ScaleNumbersStartScaleLine != value)
                {
                    m_ScaleNumbersStartScaleLine = Math.Max(value, 1);
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Browsable(true), Category("AGauge"), Description("The number of scale line steps for writing numbers.")]
        public int ScaleNumbersStepScaleLines
        {
            get { return m_ScaleNumbersStepScaleLines; }
            set
            {
                if (m_ScaleNumbersStepScaleLines != value)
                {
                    m_ScaleNumbersStepScaleLines = Math.Max(value, 1);
                    drawGaugeBackground = true;
                    Refresh();
                }
            }
        }

        [Category("AGauge"), Browsable(true), Description("The value.")]
        public float Value
        {
            get { return m_value; }
            set
            {
                if (m_value != value)
                {
                    m_value = Math.Min(Math.Max(value, m_MinValue), m_MaxValue);
                    if (base.DesignMode)
                    {
                        drawGaugeBackground = true;
                    }
                    for (var i = 0; i < 4; i++)
                    {
                        if (((m_RangeStartValue[i] <= m_value) && (m_value <= m_RangeEndValue[i])) && m_RangeEnabled[i])
                        {
                            if (!m_valueIsInRange[i] && (ValueInRangeChanged != null))
                            {
                                ValueInRangeChanged(this, new ValueInRangeChangedEventArgs(i));
                            }
                        }
                        else
                        {
                            m_valueIsInRange[i] = false;
                        }
                    }
                    Refresh();
                }
            }
        }

        [Description("This event is raised if the value falls into a defined range.")]
        public event ValueInRangeChangedDelegate ValueInRangeChanged;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void FindFontBounds()
        {
            int num2;
            var brush = new SolidBrush(Color.White);
            var brush2 = new SolidBrush(Color.Black);
            var image = new Bitmap(5, 5);
            var ef = Graphics.FromImage(image).MeasureString("0123456789", Font, -1, StringFormat.GenericTypographic);
            image = new Bitmap((int) ef.Width, (int) ef.Height);
            var graphics = Graphics.FromImage(image);
            graphics.FillRectangle(brush, 0f, 0f, ef.Width, ef.Height);
            graphics.DrawString("0123456789", Font, brush2, 0f, 0f, StringFormat.GenericTypographic);
            fontBoundY1 = 0f;
            fontBoundY2 = 0f;
            var y = 0;
            var flag = false;
            while ((y < image.Height) && !flag)
            {
                num2 = 0;
                while ((num2 < image.Width) && !flag)
                {
                    if (image.GetPixel(num2, y) != brush.Color)
                    {
                        fontBoundY1 = y;
                        flag = true;
                    }
                    num2++;
                }
                y++;
            }
            y = image.Height - 1;
            flag = false;
            while ((0 < y) && !flag)
            {
                for (num2 = 0; (num2 < image.Width) && !flag; num2++)
                {
                    if (image.GetPixel(num2, y) != brush.Color)
                    {
                        fontBoundY2 = y;
                        flag = true;
                    }
                }
                y--;
            }
        }

        private void InitializeComponent()
        {
            components = new Container();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if ((base.Width >= 10) && (base.Height >= 10))
            {
                PointF[] tfArray;
                Brush white;
                Brush brush2;
                Brush brush3;
                Brush brush4;
                Brush brush5;
                if (drawGaugeBackground)
                {
                    drawGaugeBackground = false;
                    FindFontBounds();
                    gaugeBitmap = new Bitmap(base.Width, base.Height, pe.Graphics);
                    var graphics = Graphics.FromImage(gaugeBitmap);
                    graphics.FillRectangle(new SolidBrush(BackColor), base.ClientRectangle);
                    if (BackgroundImage != null)
                    {
                        switch (BackgroundImageLayout)
                        {
                            case ImageLayout.None:
                                graphics.DrawImageUnscaled(BackgroundImage, 0, 0);
                                break;

                            case ImageLayout.Tile:
                                {
                                    var x = 0;
                                    var y = 0;
                                    while (x < base.Width)
                                    {
                                        for (y = 0; y < base.Height; y += BackgroundImage.Height)
                                        {
                                            graphics.DrawImageUnscaled(BackgroundImage, x, y);
                                        }
                                        x += BackgroundImage.Width;
                                    }
                                    break;
                                }
                            case ImageLayout.Center:
                                graphics.DrawImageUnscaled(BackgroundImage, (base.Width/2) - (BackgroundImage.Width/2),
                                                           (base.Height/2) - (BackgroundImage.Height/2));
                                break;

                            case ImageLayout.Stretch:
                                graphics.DrawImage(BackgroundImage, 0, 0, base.Width, base.Height);
                                break;

                            case ImageLayout.Zoom:
                                if ((BackgroundImage.Width/base.Width) >= (BackgroundImage.Height/base.Height))
                                {
                                    graphics.DrawImage(BackgroundImage, 0, 0, base.Width, base.Width);
                                    break;
                                }
                                graphics.DrawImage(BackgroundImage, 0, 0, base.Height, base.Height);
                                break;
                        }
                    }
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    var path = new GraphicsPath();
                    for (var i = 0; i < 5; i++)
                    {
                        if ((m_RangeEndValue[i] > m_RangeStartValue[i]) && m_RangeEnabled[i])
                        {
                            var startAngle = m_BaseArcStart +
                                             (((m_RangeStartValue[i] - m_MinValue)*m_BaseArcSweep)/
                                              (m_MaxValue - m_MinValue));
                            var sweepAngle = ((m_RangeEndValue[i] - m_RangeStartValue[i])*m_BaseArcSweep)/
                                             (m_MaxValue - m_MinValue);
                            path.Reset();
                            path.AddPie(
                                new Rectangle(m_Center.X - m_RangeOuterRadius[i], m_Center.Y - m_RangeOuterRadius[i],
                                              2*m_RangeOuterRadius[i], 2*m_RangeOuterRadius[i]), startAngle, sweepAngle);
                            path.Reverse();
                            path.AddPie(
                                new Rectangle(m_Center.X - m_RangeInnerRadius[i], m_Center.Y - m_RangeInnerRadius[i],
                                              2*m_RangeInnerRadius[i], 2*m_RangeInnerRadius[i]), startAngle, sweepAngle);
                            path.Reverse();
                            graphics.SetClip(path);
                            graphics.FillPie(new SolidBrush(m_RangeColor[i]),
                                             new Rectangle(m_Center.X - m_RangeOuterRadius[i],
                                                           m_Center.Y - m_RangeOuterRadius[i], 2*m_RangeOuterRadius[i],
                                                           2*m_RangeOuterRadius[i]), startAngle, sweepAngle);
                        }
                    }
                    graphics.SetClip(base.ClientRectangle);
                    if (m_BaseArcRadius > 0)
                    {
                        graphics.DrawArc(new Pen(m_BaseArcColor, m_BaseArcWidth),
                                         new Rectangle(m_Center.X - m_BaseArcRadius, m_Center.Y - m_BaseArcRadius,
                                                       2*m_BaseArcRadius, 2*m_BaseArcRadius), m_BaseArcStart,
                                         m_BaseArcSweep);
                    }
                    var text = "";
                    var num6 = 0f;
                    for (var j = 0; num6 <= (m_MaxValue - m_MinValue); j++)
                    {
                        text = (m_MinValue + num6).ToString(m_ScaleNumbersFormat);
                        graphics.ResetTransform();
                        var ef = graphics.MeasureString(text, Font, -1, StringFormat.GenericTypographic);
                        path.Reset();
                        path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMajorOuterRadius,
                                                      m_Center.Y - m_ScaleLinesMajorOuterRadius,
                                                      2*m_ScaleLinesMajorOuterRadius, 2*m_ScaleLinesMajorOuterRadius));
                        path.Reverse();
                        path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMajorInnerRadius,
                                                      m_Center.Y - m_ScaleLinesMajorInnerRadius,
                                                      2*m_ScaleLinesMajorInnerRadius, 2*m_ScaleLinesMajorInnerRadius));
                        path.Reverse();
                        graphics.SetClip(path);
                        graphics.DrawLine(new Pen(m_ScaleLinesMajorColor, m_ScaleLinesMajorWidth), Center.X, Center.Y,
                                          (float)
                                          (Center.X +
                                           ((2*m_ScaleLinesMajorOuterRadius)*
                                            Math.Cos(((m_BaseArcStart +
                                                       ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue)))*
                                                      3.1415926535897931)/180.0))),
                                          (float)
                                          (Center.Y +
                                           ((2*m_ScaleLinesMajorOuterRadius)*
                                            Math.Sin(((m_BaseArcStart +
                                                       ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue)))*
                                                      3.1415926535897931)/180.0))));
                        path.Reset();
                        path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorOuterRadius,
                                                      m_Center.Y - m_ScaleLinesMinorOuterRadius,
                                                      2*m_ScaleLinesMinorOuterRadius, 2*m_ScaleLinesMinorOuterRadius));
                        path.Reverse();
                        path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorInnerRadius,
                                                      m_Center.Y - m_ScaleLinesMinorInnerRadius,
                                                      2*m_ScaleLinesMinorInnerRadius, 2*m_ScaleLinesMinorInnerRadius));
                        path.Reverse();
                        graphics.SetClip(path);
                        if (num6 < (m_MaxValue - m_MinValue))
                        {
                            for (var m = 1; m <= m_ScaleLinesMinorNumOf; m++)
                            {
                                if (((m_ScaleLinesMinorNumOf%2) == 1) && (((m_ScaleLinesMinorNumOf/2) + 1) == m))
                                {
                                    path.Reset();
                                    path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesInterOuterRadius,
                                                                  m_Center.Y - m_ScaleLinesInterOuterRadius,
                                                                  2*m_ScaleLinesInterOuterRadius,
                                                                  2*m_ScaleLinesInterOuterRadius));
                                    path.Reverse();
                                    path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesInterInnerRadius,
                                                                  m_Center.Y - m_ScaleLinesInterInnerRadius,
                                                                  2*m_ScaleLinesInterInnerRadius,
                                                                  2*m_ScaleLinesInterInnerRadius));
                                    path.Reverse();
                                    graphics.SetClip(path);
                                    graphics.DrawLine(new Pen(m_ScaleLinesInterColor, m_ScaleLinesInterWidth), Center.X,
                                                      Center.Y,
                                                      (float)
                                                      (Center.X +
                                                       ((2*m_ScaleLinesInterOuterRadius)*
                                                        Math.Cos((((m_BaseArcStart +
                                                                    ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue))) +
                                                                   (((m*m_BaseArcSweep))/
                                                                    (((m_MaxValue - m_MinValue)/
                                                                      m_ScaleLinesMajorStepValue)*
                                                                     (m_ScaleLinesMinorNumOf + 1))))*3.1415926535897931)/
                                                                 180.0))),
                                                      (float)
                                                      (Center.Y +
                                                       ((2*m_ScaleLinesInterOuterRadius)*
                                                        Math.Sin((((m_BaseArcStart +
                                                                    ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue))) +
                                                                   (((m*m_BaseArcSweep))/
                                                                    (((m_MaxValue - m_MinValue)/
                                                                      m_ScaleLinesMajorStepValue)*
                                                                     (m_ScaleLinesMinorNumOf + 1))))*3.1415926535897931)/
                                                                 180.0))));
                                    path.Reset();
                                    path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorOuterRadius,
                                                                  m_Center.Y - m_ScaleLinesMinorOuterRadius,
                                                                  2*m_ScaleLinesMinorOuterRadius,
                                                                  2*m_ScaleLinesMinorOuterRadius));
                                    path.Reverse();
                                    path.AddEllipse(new Rectangle(m_Center.X - m_ScaleLinesMinorInnerRadius,
                                                                  m_Center.Y - m_ScaleLinesMinorInnerRadius,
                                                                  2*m_ScaleLinesMinorInnerRadius,
                                                                  2*m_ScaleLinesMinorInnerRadius));
                                    path.Reverse();
                                    graphics.SetClip(path);
                                }
                                else
                                {
                                    graphics.DrawLine(new Pen(m_ScaleLinesMinorColor, m_ScaleLinesMinorWidth), Center.X,
                                                      Center.Y,
                                                      (float)
                                                      (Center.X +
                                                       ((2*m_ScaleLinesMinorOuterRadius)*
                                                        Math.Cos((((m_BaseArcStart +
                                                                    ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue))) +
                                                                   (((m*m_BaseArcSweep))/
                                                                    (((m_MaxValue - m_MinValue)/
                                                                      m_ScaleLinesMajorStepValue)*
                                                                     (m_ScaleLinesMinorNumOf + 1))))*3.1415926535897931)/
                                                                 180.0))),
                                                      (float)
                                                      (Center.Y +
                                                       ((2*m_ScaleLinesMinorOuterRadius)*
                                                        Math.Sin((((m_BaseArcStart +
                                                                    ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue))) +
                                                                   (((m*m_BaseArcSweep))/
                                                                    (((m_MaxValue - m_MinValue)/
                                                                      m_ScaleLinesMajorStepValue)*
                                                                     (m_ScaleLinesMinorNumOf + 1))))*3.1415926535897931)/
                                                                 180.0))));
                                }
                            }
                        }
                        graphics.SetClip(base.ClientRectangle);
                        if (m_ScaleNumbersRotation != 0)
                        {
                            graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
                            graphics.RotateTransform((90f + m_BaseArcStart) +
                                                     ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue)));
                        }
                        graphics.TranslateTransform(
                            (float)
                            (Center.X +
                             (m_ScaleNumbersRadius*
                              Math.Cos(((m_BaseArcStart + ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue)))*
                                        3.1415926535897931)/180.0))),
                            (float)
                            (Center.Y +
                             (m_ScaleNumbersRadius*
                              Math.Sin(((m_BaseArcStart + ((num6*m_BaseArcSweep)/(m_MaxValue - m_MinValue)))*
                                        3.1415926535897931)/180.0))), MatrixOrder.Append);
                        if (j >= (ScaleNumbersStartScaleLine - 1))
                        {
                            graphics.DrawString(text, Font, new SolidBrush(m_ScaleNumbersColor), -ef.Width/2f,
                                                -fontBoundY1 - (((fontBoundY2 - fontBoundY1) + 1f)/2f),
                                                StringFormat.GenericTypographic);
                        }
                        num6 += m_ScaleLinesMajorStepValue;
                    }
                    graphics.ResetTransform();
                    graphics.SetClip(base.ClientRectangle);
                    if (m_ScaleNumbersRotation != 0)
                    {
                        graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
                    }
                    for (var k = 0; k < 5; k++)
                    {
                        if (m_CapText[k] != "")
                        {
                            graphics.DrawString(m_CapText[k], Font, new SolidBrush(m_CapColor[k]), m_CapPosition[k].X,
                                                m_CapPosition[k].Y, StringFormat.GenericTypographic);
                        }
                    }
                }
                pe.Graphics.DrawImageUnscaled(gaugeBitmap, 0, 0);
                pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                pe.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                float num10 = (m_BaseArcStart +
                               ((int) (((m_value - m_MinValue)*m_BaseArcSweep)/(m_MaxValue - m_MinValue))))%360;
                var d = (num10*3.1415926535897931)/180.0;
                switch (m_NeedleType)
                {
                    case 0:
                        {
                            tfArray = new PointF[3];
                            white = Brushes.White;
                            brush2 = Brushes.White;
                            brush3 = Brushes.White;
                            brush4 = Brushes.White;
                            brush5 = Brushes.White;
                            var green = (int) ((((num10 + 225f)%180f)*100f)/180f);
                            var num13 = (int) ((((num10 + 135f)%180f)*100f)/180f);
                            pe.Graphics.FillEllipse(new SolidBrush(m_NeedleColor2), (Center.X - (m_NeedleWidth*3)),
                                                    (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6), (m_NeedleWidth*6));
                            switch (m_NeedleColor1)
                            {
                                case NeedleColorEnum.Gray:
                                    white = new SolidBrush(Color.FromArgb(80 + green, 80 + green, 80 + green));
                                    brush2 = new SolidBrush(Color.FromArgb(180 - green, 180 - green, 180 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(80 + num13, 80 + num13, 80 + num13));
                                    brush4 = new SolidBrush(Color.FromArgb(180 - num13, 180 - num13, 180 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Gray, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Red:
                                    white = new SolidBrush(Color.FromArgb(0x91 + green, green, green));
                                    brush2 = new SolidBrush(Color.FromArgb(0xf5 - green, 100 - green, 100 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(0x91 + num13, num13, num13));
                                    brush4 = new SolidBrush(Color.FromArgb(0xf5 - num13, 100 - num13, 100 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Red, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Green:
                                    white = new SolidBrush(Color.FromArgb(green, 0x91 + green, green));
                                    brush2 = new SolidBrush(Color.FromArgb(100 - green, 0xf5 - green, 100 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(num13, 0x91 + num13, num13));
                                    brush4 = new SolidBrush(Color.FromArgb(100 - num13, 0xf5 - num13, 100 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Green, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Blue:
                                    white = new SolidBrush(Color.FromArgb(green, green, 0x91 + green));
                                    brush2 = new SolidBrush(Color.FromArgb(100 - green, 100 - green, 0xf5 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(num13, num13, 0x91 + num13));
                                    brush4 = new SolidBrush(Color.FromArgb(100 - num13, 100 - num13, 0xf5 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Blue, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Yellow:
                                    white = new SolidBrush(Color.FromArgb(0x91 + green, 0x91 + green, green));
                                    brush2 = new SolidBrush(Color.FromArgb(0xf5 - green, 0xf5 - green, 100 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(0x91 + num13, 0x91 + num13, num13));
                                    brush4 = new SolidBrush(Color.FromArgb(0xf5 - num13, 0xf5 - num13, 100 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Violet, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Violet:
                                    white = new SolidBrush(Color.FromArgb(0x91 + green, green, 0x91 + green));
                                    brush2 = new SolidBrush(Color.FromArgb(0xf5 - green, 100 - green, 0xf5 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(0x91 + num13, num13, 0x91 + num13));
                                    brush4 = new SolidBrush(Color.FromArgb(0xf5 - num13, 100 - num13, 0xf5 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Violet, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;

                                case NeedleColorEnum.Magenta:
                                    white = new SolidBrush(Color.FromArgb(green, 0x91 + green, 0x91 + green));
                                    brush2 = new SolidBrush(Color.FromArgb(100 - green, 0xf5 - green, 0xf5 - green));
                                    brush3 = new SolidBrush(Color.FromArgb(num13, 0x91 + num13, 0x91 + num13));
                                    brush4 = new SolidBrush(Color.FromArgb(100 - num13, 0xf5 - num13, 0xf5 - num13));
                                    pe.Graphics.DrawEllipse(Pens.Magenta, (Center.X - (m_NeedleWidth*3)),
                                                            (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6),
                                                            (m_NeedleWidth*6));
                                    break;
                            }
                            break;
                        }
                    case 1:
                        {
                            var point = new Point(Center.X - ((int) ((m_NeedleRadius/8)*Math.Cos(d))),
                                                  Center.Y - ((int) ((m_NeedleRadius/8)*Math.Sin(d))));
                            var point2 = new Point(Center.X + ((int) (m_NeedleRadius*Math.Cos(d))),
                                                   Center.Y + ((int) (m_NeedleRadius*Math.Sin(d))));
                            pe.Graphics.FillEllipse(new SolidBrush(m_NeedleColor2), (Center.X - (m_NeedleWidth*3)),
                                                    (Center.Y - (m_NeedleWidth*3)), (m_NeedleWidth*6), (m_NeedleWidth*6));
                            switch (m_NeedleColor1)
                            {
                                case NeedleColorEnum.Gray:
                                    pe.Graphics.DrawLine(new Pen(Color.DarkGray, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.DarkGray, m_NeedleWidth), Center.X, Center.Y,
                                                         point.X, point.Y);
                                    return;

                                case NeedleColorEnum.Red:
                                    pe.Graphics.DrawLine(new Pen(Color.Red, m_NeedleWidth), Center.X, Center.Y, point2.X,
                                                         point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Red, m_NeedleWidth), Center.X, Center.Y, point.X,
                                                         point.Y);
                                    return;

                                case NeedleColorEnum.Green:
                                    pe.Graphics.DrawLine(new Pen(Color.Green, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Green, m_NeedleWidth), Center.X, Center.Y,
                                                         point.X, point.Y);
                                    return;

                                case NeedleColorEnum.Blue:
                                    pe.Graphics.DrawLine(new Pen(Color.Blue, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Blue, m_NeedleWidth), Center.X, Center.Y, point.X,
                                                         point.Y);
                                    return;

                                case NeedleColorEnum.Yellow:
                                    pe.Graphics.DrawLine(new Pen(Color.Yellow, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Yellow, m_NeedleWidth), Center.X, Center.Y,
                                                         point.X, point.Y);
                                    return;

                                case NeedleColorEnum.Violet:
                                    pe.Graphics.DrawLine(new Pen(Color.Violet, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Violet, m_NeedleWidth), Center.X, Center.Y,
                                                         point.X, point.Y);
                                    return;

                                case NeedleColorEnum.Magenta:
                                    pe.Graphics.DrawLine(new Pen(Color.Magenta, m_NeedleWidth), Center.X, Center.Y,
                                                         point2.X, point2.Y);
                                    pe.Graphics.DrawLine(new Pen(Color.Magenta, m_NeedleWidth), Center.X, Center.Y,
                                                         point.X, point.Y);
                                    return;
                            }
                            return;
                        }
                    default:
                        return;
                }
                if (Math.Floor(((float) ((((num10 + 225f)%360f))/180.0))) == 0.0)
                {
                    brush5 = white;
                    white = brush2;
                    brush2 = brush5;
                }
                if (Math.Floor(((float) ((((num10 + 135f)%360f))/180.0))) == 0.0)
                {
                    brush4 = brush3;
                }
                tfArray[0].X = (float) (Center.X + (m_NeedleRadius*Math.Cos(d)));
                tfArray[0].Y = (float) (Center.Y + (m_NeedleRadius*Math.Sin(d)));
                tfArray[1].X = (float) (Center.X - ((m_NeedleRadius/20)*Math.Cos(d)));
                tfArray[1].Y = (float) (Center.Y - ((m_NeedleRadius/20)*Math.Sin(d)));
                tfArray[2].X =
                    (float)
                    ((Center.X - ((m_NeedleRadius/5)*Math.Cos(d))) +
                     ((m_NeedleWidth*2)*Math.Cos(d + 1.5707963267948966)));
                tfArray[2].Y =
                    (float)
                    ((Center.Y - ((m_NeedleRadius/5)*Math.Sin(d))) +
                     ((m_NeedleWidth*2)*Math.Sin(d + 1.5707963267948966)));
                pe.Graphics.FillPolygon(white, tfArray);
                tfArray[2].X =
                    (float)
                    ((Center.X - ((m_NeedleRadius/5)*Math.Cos(d))) +
                     ((m_NeedleWidth*2)*Math.Cos(d - 1.5707963267948966)));
                tfArray[2].Y =
                    (float)
                    ((Center.Y - ((m_NeedleRadius/5)*Math.Sin(d))) +
                     ((m_NeedleWidth*2)*Math.Sin(d - 1.5707963267948966)));
                pe.Graphics.FillPolygon(brush2, tfArray);
                tfArray[0].X = (float) (Center.X - (((m_NeedleRadius/20) - 1)*Math.Cos(d)));
                tfArray[0].Y = (float) (Center.Y - (((m_NeedleRadius/20) - 1)*Math.Sin(d)));
                tfArray[1].X =
                    (float)
                    ((Center.X - ((m_NeedleRadius/5)*Math.Cos(d))) +
                     ((m_NeedleWidth*2)*Math.Cos(d + 1.5707963267948966)));
                tfArray[1].Y =
                    (float)
                    ((Center.Y - ((m_NeedleRadius/5)*Math.Sin(d))) +
                     ((m_NeedleWidth*2)*Math.Sin(d + 1.5707963267948966)));
                tfArray[2].X =
                    (float)
                    ((Center.X - ((m_NeedleRadius/5)*Math.Cos(d))) +
                     ((m_NeedleWidth*2)*Math.Cos(d - 1.5707963267948966)));
                tfArray[2].Y =
                    (float)
                    ((Center.Y - ((m_NeedleRadius/5)*Math.Sin(d))) +
                     ((m_NeedleWidth*2)*Math.Sin(d - 1.5707963267948966)));
                pe.Graphics.FillPolygon(brush4, tfArray);
                tfArray[0].X = (float) (Center.X - ((m_NeedleRadius/20)*Math.Cos(d)));
                tfArray[0].Y = (float) (Center.Y - ((m_NeedleRadius/20)*Math.Sin(d)));
                tfArray[1].X = (float) (Center.X + (m_NeedleRadius*Math.Cos(d)));
                tfArray[1].Y = (float) (Center.Y + (m_NeedleRadius*Math.Sin(d)));
                pe.Graphics.DrawLine(new Pen(m_NeedleColor2), Center.X, Center.Y, tfArray[0].X, tfArray[0].Y);
                pe.Graphics.DrawLine(new Pen(m_NeedleColor2), Center.X, Center.Y, tfArray[1].X, tfArray[1].Y);
            }
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
        }

        protected override void OnResize(EventArgs e)
        {
            drawGaugeBackground = true;
            Refresh();
        }

        #region Nested type: ValueInRangeChangedEventArgs

        public class ValueInRangeChangedEventArgs : EventArgs
        {
            public int valueInRange;

            public ValueInRangeChangedEventArgs(int valueInRange)
            {
                this.valueInRange = valueInRange;
            }
        }

        #endregion
    }
}